# encoding:utf-8
from flask import Flask, render_template, url_for, request, json, jsonify
# from flask_cors import CORS
from model import *
app = Flask(__name__)
# 设置编码
app.config['JSON_AS_ASCII'] = False
# CORS(app)

# 接收参数，并返回json数据
@app.route('/get_vector', methods=['POST'])
def form_data():
    # 从request中获取表单请求的参数信息
    json_data = request.get_json()
    print(json_data)
    vectors = generate_vector(json_data)

    return_data = []
    for item, v in zip(json_data, vectors):
        return_data.append(v)
    return jsonify(return_data)

def generate_vector(jsons):

    properties = jsons["properties"]
    data = jsons["data"]
    lines = []
    for item in data:
        combined = " ".join([item[property] for property in properties])
        lines.append(combined)
    return encode(lines)

def init():
    print('tret')

if __name__ == '__main__':

    init()
    app.run()